package com.xsm.ppsecret.widgets;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.xsm.ppsecret.R;

/**
 * Author: Xiasem
 * Email: xiasem@163.com
 * Date: 17-5-16.
 */

public class DeleteDialog extends Dialog implements View.OnClickListener {

    public static int defaultHeight = 285;
    public static int defaultWidth = 145;
    private Context mContext;
    private DeleteListener mDeleteListener;

    public DeleteDialog(Context context, int style, DeleteListener deleteListener) {
        this(context, defaultWidth, defaultHeight, style);
        mContext = context;
        mDeleteListener = deleteListener;
    }

    public DeleteDialog(Context context, int width, int height, int style) {
        super(context, style);
        //加载布局
        Window window = getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
        params.gravity = Gravity.CENTER;
        if (height != 0) {
            params.height = height;
        } else {
            params.height = defaultHeight;
        }
        if (width != 0) {
            params.width = width;
        } else {
            params.width = defaultWidth;
        }
        window.setAttributes(params);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LayoutInflater inflater = (LayoutInflater) mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.dialog_delete, null);
        this.setContentView(view);
        view.findViewById(R.id.dialog_delete_cancel).setOnClickListener(this);
        view.findViewById(R.id.dialog_delete_confirm).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.dialog_delete_cancel:
                DeleteDialog.this.dismiss();
                break;
            case R.id.dialog_delete_confirm:
                mDeleteListener.confirm();
                DeleteDialog.this.dismiss();
                break;
        }
    }

    public interface DeleteListener {
        void confirm();
    }

}
